package com.srd.phone.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.shengrongdai.srd.R;

/**
 * 还款成功
 */
public class ReturnSucceedActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_time_value;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_return_succeed);
        tv_time_value = (TextView) findViewById(R.id.tv_time_value);
        findViewById(R.id.tv_dialog_activity_exit).setOnClickListener(this);
        downTimer.start();
    }

    CountDownTimer downTimer = new CountDownTimer(1000 * 11, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            long second = millisUntilFinished / 1000;
            setTextSpan(tv_time_value, second + "s");
        }

        @Override
        public void onFinish() {
            finish();
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_dialog_activity_exit:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        downTimer.cancel();
        downTimer = null;
    }

    public void setTextSpan(TextView tv, String strs) {
        tv.setText("还款成功");
        String value = strs;
        SpannableString sb = new SpannableString(value);
        sb.setSpan(new AbsoluteSizeSpan(14, true), 0, value.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        sb.setSpan(new ForegroundColorSpan(Color.parseColor("#ed8400")), 0, value.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tv.append(sb);
        value = "内自动返回";
        sb = new SpannableString(value);
        sb.setSpan(new AbsoluteSizeSpan(14, true), 0, value.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        sb.setSpan(new ForegroundColorSpan(Color.BLACK), 0, value.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tv.append(sb);
    }
}
